import QtQuick 2.0
import QtQuick.Window 2.3
import QtQuick.Controls 2.0
import SparkUI 1.0

Window {
    id: root
    visible: true

    maximumWidth: 944
    maximumHeight: 640
    minimumWidth: 944
    minimumHeight: 640

    title: "自定义控件预览 - v0.0.1"

    Background {
        id: background
        anchors.fill: parent
    
        Component.onCompleted: background.init();

        MagicPool {
            id: magicPool
            anchors.fill: parent

            Timer {
                id: timer
                interval: 3000
                repeat: true
                running: true
                onTriggered: {
                    if (Math.random() > 0.6 && !magicPool.moving) randomMove();
                }

                function randomMove() {
                    var r_x = Math.random() * magicPool.width;
                    var r_y = Math.random() * magicPool.height;
                    magicPool.moveFish(r_x, r_y, false);
                }

                Component.onCompleted: {
                    randomMove()
                }
            }
            
            MouseArea {
                id: fish_mouse
                anchors.fill: parent

                hoverEnabled: true

                onClicked: magicPool.moveFish(mouse.x, mouse.y, true);
                
                onMouseXChanged: {
                    // if(!magicPool.moving) magicPool.moveFish(mouse.x, mouse.y, true);
                    if (containsMouse) {
                        background.mousePos(mouseX, mouseY);
                    }
                }
            }
            
        }
    }

    FileWatcher {
        id: fileWatcher
        filePath: "main.qml"  // 要监视的文件路径

        onFileChanged: {
            console.log("File changed:", filePath)
            timer.randomMove()
        }

        Component.onCompleted: {
            // 自动开始监视
            fileWatcher.startWatching()
        }
    }
}

